package com.example.protestgps;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import android.os.AsyncTask;
import android.util.Log;

public class PostRegister {

	String _user;
	String _mobileno;
	String _namesurname;

	PostRegis postre = new PostRegis();

	public void dataregister(String user, String mobileno,String namesurname) {

		this._user = user;
		this._mobileno = mobileno;
		this._namesurname = namesurname;

	}

	public class PostRegis extends AsyncTask<String, String, String> {

		@Override
		protected String doInBackground(String... urls) {
			// TODO Auto-generated method stub
			String result = "";
			ArrayList<NameValuePair> data = new ArrayList<NameValuePair>();
			data.add(new BasicNameValuePair("user", ""+_user));
			data.add(new BasicNameValuePair("mobileno", ""+_mobileno));
			data.add(new BasicNameValuePair("namesurname", ""+_namesurname));
			HttpClient client = new DefaultHttpClient();
			HttpPost post = new  HttpPost(urls[0]);
			try {
				
				post.setEntity(new UrlEncodedFormEntity(data,HTTP.UTF_8));
				HttpResponse response = client.execute(post);
				HttpEntity entity = response.getEntity();
			
				if(entity != null){
					InputStream inputStream = entity.getContent();
					BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
					StringBuilder sb = new StringBuilder();
					String line = null;
					
					
					while((line = reader.readLine()) != null){
						sb.append(line + "\n");
					}
					
					
					inputStream.close();
					result = sb.toString();
					Log.d("resultt",""+result);
				}				
			} catch (Exception e) {
				e.printStackTrace();
		}
			return null;
		}

	}

}
